﻿using System;
using System.Web.Mvc;
using Sharp.DataTransferObject.CMS;
using Sharp.Infrastructure;
using Sharp.Infrastructure.Communication;
using Sharp.Platform.Mvc;
using Sharp.ServiceContracts.CMS;
using Sharp.WebBooter.Areas.CMS.Models;

namespace Sharp.WebBooter.Areas.CMS.Controllers
{
    public class IPBlackListController : Controller
    {
        // GET: Control/IPBlackList
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 分页数据
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetPaged(DataTableParameter param)
        {
            using (var proxy = new ServiceProxy<IMemberService>())
            {

                var page = proxy.Channel.GetIPBlackListPaged(param.ToPagingFeature());

                return this.Store(page);
            }
        }
        [Permission(Name = "新增", Order = 1)]
        public ActionResult Create()
        {
            return View("Edit", new IPBlackListViewModel());
        }


        [Permission(Name = "编辑", Order = 2)]
        public ActionResult Edit(Guid id)
        {
            using (var proxy = new ServiceProxy<IMemberService>())
            {
                var model = proxy.Channel.GetIPBlackListInfo(id).Data.To<IPBlackListViewModel>();

                return View("Edit", model);
            }
        }


        [HttpPost]
        public ActionResult Save(IPBlackListDTO vm)
        {
            if (vm == null)
            {
                return this.JsonNet(new Result() { Err = "提交数据出错。" });
            }
            using (var proxy = new ServiceProxy<IMemberService>())
            {

                var res = proxy.Channel.SaveIPBlackList(vm);

                return this.JsonNet(res);
            }
        }

        [HttpPost]
        [Permission(Name = "删除", Order = 3)]
        public ActionResult Delete(Guid[] ids, FormCollection collection)
        {
            using (var proxy = new ServiceProxy<IMemberService>())
            {
                var res = proxy.Channel.DeleteIPBlackLists(ids);
                return this.JsonNet(res);
            }
        }
    }
}